package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-26
 * Time: 15:58
 */

public class Demo1 {
    private static int total = 0;

    public static void main(String[] args) throws InterruptedException {
        // 直接使用 Runnable 实现上述 1 + 2 +...+100 的功能
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 1; i <= 100; i++) {
                    sum += i;
                }
                total = sum;
            }
        };

        Thread t = new Thread(runnable);
        t.start();
        t.join();
        System.out.println("total = " + total);
    }
}
